#include "TestCamera.h"

#include "xwpch.h"
#include "Core/Application.h"

TestCamera::TestCamera()
{
}

TestCamera::~TestCamera()
{

}

glm::mat4 TestCamera::GetViewMatrix()
{
    return glm::lookAt(Location , *Target, Up);
}

void TestCamera::ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch)
{
    double DetaTime = Application::Get().GetDeltaTime();
    float x = xoffset * DetaTime * MouseSensitivity;
    float y = yoffset * DetaTime * MouseSensitivity;

    Yaw += x;
    Pitch -= y;


    if (constrainPitch)
    {
        if (Pitch > 89.0f)
            Pitch = 89.0f;
        if (Pitch < -89.0f)
            Pitch = -89.0f;
    }

    glm::vec3 front;
    front.x = radius * cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
    front.y = radius * sin(glm::radians(Pitch));
    front.z = radius * sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));

    Location = *Target + front;

    Forward = glm::normalize(*Target - Location);

    Right = glm::normalize(glm::cross(Forward, WorldUp));  // normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
    Up = glm::normalize(glm::cross(Right, Forward));
}
